﻿#include "math.h"

Math::Math(QObject *parent) : QObject(parent)
{

}

int Math::generateRandomNumber(int min, int max)
{
    if(min == max && min ==0){
           return 0;
    }
    return (rand() % (max - min)) + min +1;
}

int Math::doCount(int num1, int num2, QString op)
{
    if(op == "+"){
       return num1+num2;
    }else if("-" == op){
        return num1-num2;
    }else if("*" == op){
        return num1*num2;
    }
    return 0;
}
// 先乘后加减 a*b+c
const QString Math::fun1()
{
    int num1 = generateRandomNumber(2, 7);
    int num2 = generateRandomNumber(2, 7);
    int num3 = generateRandomNumber(10, 50);
    QString tmp = QString::number(num1) + " * " +  QString::number(num2) + " + "+  QString::number(num3)+" = ";
    return tmp;
}
// 先乘后加减 a*b-c
const QString Math::fun2()
{
     QString tmp ;
     int num1 ,num2,num3;
     do{
      num1 = generateRandomNumber(2, 7);
      num2 = generateRandomNumber(2, 7);
      num3 = generateRandomNumber(10, 100);

     }while(num1 * num2 < num3);
    tmp = QString::number(num1) + " * " +  QString::number(num2) + " - "+  QString::number(num3)+ " = ";
    return tmp;
}
// 先乘后加减 a/b+c
const QString Math::fun3()
{
    QString tmp ;
    int num1 ,num2,num3;

   num1 = generateRandomNumber(2, 6);
   num2 = generateRandomNumber(2, 6);
   num3 = generateRandomNumber(10, 50);
   tmp = QString::number(num1*num2) + " ÷ " +  QString::number(num2) + " + "+  QString::number(num3)+ " = ";
   return tmp;
}
// 先除后减 a÷b-c
const QString Math::fun4()
{
    QString tmp ;
    int num1 ,num2,num3;
    do{
     num1 = generateRandomNumber(2, 6);
     num2 = generateRandomNumber(2, 6);
     num3 = generateRandomNumber(2, 6);

   }while(num1 < num3);
   tmp = QString::number(num1*num2) + " ÷ " +  QString::number(num2) + " - "+  QString::number(num3)+ " = ";
   return tmp;
}
